<?php
/**
 * update部门
 */
apf_require_controller("HrAbstract");

class Hr_Ajax_GetDepartmentJobController extends HrAbstractController {

    public function handle_request() {
        $result = array();
        $params = $this->request->get_parameters();
        $this->_check_params($params);

        $job_bll = new Bll_Hr_Job();
        if(!isset($params['skill'])){
            $tmp_result = $job_bll->get_job_by_dep($params['departID']);
            $result = array();
            foreach($tmp_result as $k=>$val){
                $val['list_url']='';
                if($val['fact_num']){
                    $val['list_url'] = Util_BaseUrls::staff_list_url()."?jobid=".$val['job_id'];
                }
                $result[$k]=$val;
            }
        }else{
            $pos_bll = new Bll_Hr_Position();
            $result = $pos_bll->get_position_by_function(intval($params['skill']));
            if($result){
                $job_ids = array_keys($result);
                $pos_bll = new Bll_Hr_Position();
                $pos_infos = $pos_bll->get_position_by_ids($job_ids);

                foreach($result as &$row){
                    $row['job_id']   = $row['position_id'];//实际上是职位类型的ID，position_id
                    $row['job_name'] = $pos_infos[$row['position_id']]['position_name'];//实际上是职位类型的名称，position_name
                    unset($row['is_deleted']);
                    unset($row['created']);
                    unset($row['last_update']);
                }
            }
        }

        $this->json_encode(1,$result);
    }
    /**
     * 参数检测
     */
    private function _check_params($params){
        $depart = $params['departID'];
        $status=0;
        if(empty($depart)){
            $this->json_encode($status,Const_Tip::ERROR_PARAM);
        }
        return true;
    }
}